package com.qf.flash.ui.home.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qf.dblib.dao.impl.UserMgr;
import com.qf.flash.R;
import com.qf.flash.constant.FlashCodes;
import com.qf.flash.http.response.GameDetailResponse;
import com.qf.flash.utils.ImageLoader;
import com.qf.flashlib.adapter.BaseRViewItem;
import com.qf.flashlib.adapter.RViewHolder;
import com.qf.flashlib.util.ViewUtil;

import java.util.ArrayList;

/**
 * 2020/2/24 16:38
 */
public class GroupMemberItem extends BaseRViewItem<Object> {

    @Override
    public boolean isItemView(Object entity, int position) {
        return entity instanceof GameDetailResponse.UsersBean;
    }

    @Override
    public int getItemLayout() {
        return R.layout.item_group_member;
    }

    @Override
    public void convert(RViewHolder holder, Object entity, int position, int itemSize) {
        GameDetailResponse.UsersBean userInfo = (GameDetailResponse.UsersBean) entity;
        ImageView ivHead = holder.getView(R.id.iv_head);
        ImageView ivDec = holder.getView(R.id.iv_dec);
        TextView tvName = holder.getView(R.id.tv_name);
        TextView tvLevel = holder.getView(R.id.tv_level);
        TextView tv_role_in_game = holder.getView(R.id.tv_role_in_game);
        ImageLoader.loadCircleHead(holder.getmConvertView().getContext(), userInfo.getPhoto(), ivHead);
        tvName.setText(userInfo.getName());
        Glide.with(ivDec).load(userInfo.getPhotoLineImage()).into(ivDec);
        ViewUtil.setRightIcon(tvName, FlashCodes.SEX_FEMALE.equals(userInfo.getSex()) ? R.mipmap.icon_woman : R.mipmap.icon_man, 15);
        String level = "Lv." + userInfo.getLevel();
        tvLevel.setText(level);
        setScoreEvlaute(holder, userInfo.getPlayEvaluate());
        if (userInfo.getUserType().contains("0")) {
            tv_role_in_game.setVisibility(View.GONE);
        } else {
            tv_role_in_game.setVisibility(View.VISIBLE);
            if (userInfo.getUserType().contains("2")) {
                tv_role_in_game.setText("队长");
            } else{
                tv_role_in_game.setText("商家");
            }
        }
        UserMgr.getInstance().getLoginUser().getUid();
    }

    private void setScoreEvlaute(RViewHolder holder, ArrayList<Integer> playEvaluates) {
        if (playEvaluates.contains(FlashCodes.SCORE_BEAUTY)) {
            holder.getView(R.id.tv_evaluate_beauty).setVisibility(View.VISIBLE);
        } else {
            holder.getView(R.id.tv_evaluate_beauty).setVisibility(View.GONE);
        }
        if (playEvaluates.contains(FlashCodes.SCORE_COURAGE)) {
            holder.getView(R.id.tv_evaluate_courage).setVisibility(View.VISIBLE);
        } else {
            holder.getView(R.id.tv_evaluate_courage).setVisibility(View.GONE);
        }
        if (playEvaluates.contains(FlashCodes.SCORE_MVP)) {
            holder.getView(R.id.tv_evaluate_mvp).setVisibility(View.VISIBLE);
        } else {
            holder.getView(R.id.tv_evaluate_mvp).setVisibility(View.GONE);
        }
        if (playEvaluates.contains(FlashCodes.SCORE_WISDOM)) {
            holder.getView(R.id.tv_evaluate_wisdom).setVisibility(View.VISIBLE);
        } else {
            holder.getView(R.id.tv_evaluate_wisdom).setVisibility(View.GONE);
        }

    }
}
